home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / messenger.jar.z / messenger.jar / content / messenger-smime / msgReadSecurityInfo.js < prev    next >
Text File  |  2003-11-11  |  8KB  |  265 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla Communicator.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corp..
  19.  * Portions created by the Initial Developer are Copyright (C) 2002
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s): Kai Engert <kaie@netscape.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock;
  39. const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
  40. const nsIX509Cert = Components.interfaces.nsIX509Cert;
  41. const nsICMSMessageErrors = Components.interfaces.nsICMSMessageErrors;
  42. const nsICertificateDialogs = Components.interfaces.nsICertificateDialogs;
  43. const nsCertificateDialogs = "@mozilla.org/nsCertificateDialogs;1"
  44.  
  45. var gSignerCert = null;
  46. var gEncryptionCert = null;
  47.  
  48. var gSignatureStatus = -1;
  49. var gEncryptionStatus = -1;
  50.  
  51. var params = null;
  52.  
  53. function setText(id, value) {
  54.   var element = document.getElementById(id);
  55.   if (!element)
  56.     return;
  57.   if (element.hasChildNodes())
  58.     element.removeChild(element.firstChild);
  59.   var textNode = document.createTextNode(value);
  60.   element.appendChild(textNode);
  61. }
  62.  
  63. function onLoad()
  64. {
  65.   document.getElementById("cancel").setAttribute("collapsed", "true");
  66.  
  67.   var pkiParams = window.arguments[0].QueryInterface(nsIPKIParamBlock);
  68.   var isupport = pkiParams.getISupportAtIndex(1);
  69.   if (isupport) {
  70.     gSignerCert = isupport.QueryInterface(nsIX509Cert);
  71.   }
  72.   isupport = pkiParams.getISupportAtIndex(2);
  73.   if (isupport) {
  74.     gEncryptionCert = isupport.QueryInterface(nsIX509Cert);
  75.   }
  76.   
  77.   params = pkiParams.QueryInterface(nsIDialogParamBlock);
  78.   
  79.   gSignatureStatus = params.GetInt(1);
  80.   gEncryptionStatus = params.GetInt(2);
  81.   
  82.   var bundle = document.getElementById("bundle_smime_read_info");
  83.  
  84.   if (bundle) {
  85.     var sigInfoLabel = null;
  86.     var sigInfoHeader = null;
  87.     var sigInfo = null;
  88.     var sigInfo_clueless = false;
  89.  
  90.     switch (gSignatureStatus) {
  91.       case -1:
  92.       case nsICMSMessageErrors.VERIFY_NOT_SIGNED:
  93.         sigInfoLabel = "SINoneLabel";
  94.         sigInfo = "SINone";
  95.         break;
  96.  
  97.       case nsICMSMessageErrors.SUCCESS:
  98.         sigInfoLabel = "SIValidLabel";
  99.         sigInfo = "SIValid";
  100.         break;
  101.  
  102.  
  103.       case nsICMSMessageErrors.VERIFY_BAD_SIGNATURE:
  104.       case nsICMSMessageErrors.VERIFY_DIGEST_MISMATCH:
  105.         sigInfoLabel = "SIInvalidLabel";
  106.         sigInfoHeader = "SIInvalidHeader";
  107.         sigInfo = "SIContentAltered";
  108.         break;
  109.  
  110.       case nsICMSMessageErrors.VERIFY_UNKNOWN_ALGO:
  111.       case nsICMSMessageErrors.VERIFY_UNSUPPORTED_ALGO:
  112.         sigInfoLabel = "SIInvalidLabel";
  113.         sigInfoHeader = "SIInvalidHeader";
  114.         sigInfo = "SIInvalidCipher";
  115.         break;
  116.  
  117.       case nsICMSMessageErrors.VERIFY_HEADER_MISMATCH:
  118.         sigInfoLabel = "SIPartiallyValidLabel";
  119.         sigInfoHeader = "SIPartiallyValidHeader";
  120.         sigInfo = "SIHeaderMismatch";
  121.         break;
  122.  
  123.       case nsICMSMessageErrors.VERIFY_CERT_WITHOUT_ADDRESS:
  124.         sigInfoLabel = "SIPartiallyValidLabel";
  125.         sigInfoHeader = "SIPartiallyValidHeader";
  126.         sigInfo = "SICertWithoutAddress";
  127.         break;
  128.  
  129.       case nsICMSMessageErrors.VERIFY_UNTRUSTED:
  130.         sigInfoLabel = "SIInvalidLabel";
  131.         sigInfoHeader = "SIInvalidHeader";
  132.         sigInfo = "SIUntrustedCA";
  133.         // XXX Need to extend to communicate better errors
  134.         // might also be:
  135.         // SIExpired SIRevoked SINotYetValid SIUnknownCA SIExpiredCA SIRevokedCA SINotYetValidCA
  136.         break;
  137.  
  138.       case nsICMSMessageErrors.VERIFY_NOT_YET_ATTEMPTED:
  139.       case nsICMSMessageErrors.GENERAL_ERROR:
  140.       case nsICMSMessageErrors.VERIFY_NO_CONTENT_INFO:
  141.       case nsICMSMessageErrors.VERIFY_BAD_DIGEST:
  142.       case nsICMSMessageErrors.VERIFY_NOCERT:
  143.       case nsICMSMessageErrors.VERIFY_ERROR_UNVERIFIED:
  144.       case nsICMSMessageErrors.VERIFY_ERROR_PROCESSING:
  145.       case nsICMSMessageErrors.VERIFY_MALFORMED_SIGNATURE:
  146.         sigInfoLabel = "SIInvalidLabel";
  147.         sigInfoHeader = "SIInvalidHeader";
  148.         sigInfo_clueless = true;
  149.         break;
  150.     }
  151.  
  152.     
  153.     document.getElementById("signatureLabel").value = 
  154.       bundle.getString(sigInfoLabel);
  155.  
  156.     var label;
  157.     if (sigInfoHeader) {
  158.       label = document.getElementById("signatureHeader");
  159.       label.collapsed = false;
  160.       label.value = bundle.getString(sigInfoHeader);
  161.     }
  162.     
  163.     var str;
  164.     if (sigInfo) {
  165.       str = bundle.getString(sigInfo);
  166.     }
  167.     else if (sigInfo_clueless) {
  168.       str = bundle.getString("SIClueless") + " (" + gSignatureStatus + ")";
  169.     }
  170.     setText("signatureExplanation", str);
  171.     
  172.  
  173.     var encInfoLabel = null;
  174.     var encInfoHeader = null;
  175.     var encInfo = null;
  176.     var encInfo_clueless = false;
  177.  
  178.     switch (gEncryptionStatus) {
  179.       case -1:
  180.         encInfoLabel = "EINoneLabel";
  181.         encInfo = "EINone";
  182.         break;
  183.  
  184.       case nsICMSMessageErrors.SUCCESS:
  185.         encInfoLabel = "EIValidLabel";
  186.         encInfo = "EIValid";
  187.         break;
  188.  
  189.       case nsICMSMessageErrors.GENERAL_ERROR:
  190.         encInfoLabel = "EIInvalidLabel";
  191.         encInfoHeader = "EIInvalidHeader";
  192.         encInfo_clueless = 1;
  193.         break;
  194.     }
  195.  
  196.  
  197.     document.getElementById("encryptionLabel").value = 
  198.       bundle.getString(encInfoLabel);
  199.  
  200.     if (encInfoHeader) {
  201.       label = document.getElementById("encryptionHeader");
  202.       label.collapsed = false;
  203.       label.value = bundle.getString(encInfoHeader);
  204.     }
  205.     
  206.     if (encInfo) {
  207.       str = bundle.getString(encInfo);
  208.     }
  209.     else if (encInfo_clueless) {
  210.       str = bundle.getString("EIClueless");
  211.     }
  212.     setText("encryptionExplanation", str);
  213.   }
  214.   
  215.   if (gSignerCert) {
  216.     document.getElementById("signatureCert").collapsed = false;
  217.     if (gSignerCert.subjectName) {
  218.       document.getElementById("signedBy").value = gSignerCert.commonName;
  219.     }
  220.     if (gSignerCert.emailAddress) {
  221.       document.getElementById("signerEmail").value = gSignerCert.emailAddress;
  222.     }
  223.     if (gSignerCert.issuerName) {
  224.       document.getElementById("sigCertIssuedBy").value = gSignerCert.issuerCommonName;
  225.     }
  226.   }
  227.  
  228.   if (gEncryptionCert) {
  229.     document.getElementById("encryptionCert").collapsed = false;
  230.     if (gEncryptionCert.subjectName) {
  231.       document.getElementById("encryptedFor").value = gEncryptionCert.commonName;
  232.     }
  233.     if (gEncryptionCert.emailAddress) {
  234.       document.getElementById("recipientEmail").value = gEncryptionCert.emailAddress;
  235.     }
  236.     if (gEncryptionCert.issuerName) {
  237.       document.getElementById("encCertIssuedBy").value = gEncryptionCert.issuerCommonName;
  238.     }
  239.   }
  240. }
  241.  
  242. function viewCertHelper(parent, cert) {
  243.   var cd = Components.classes[nsCertificateDialogs].getService(nsICertificateDialogs);
  244.   cd.viewCert(parent, cert);
  245. }
  246.  
  247. function viewSignatureCert()
  248. {
  249.   if (gSignerCert) {
  250.     viewCertHelper(window, gSignerCert);
  251.   }
  252. }
  253.  
  254. function viewEncryptionCert()
  255. {
  256.   if (gEncryptionCert) {
  257.     viewCertHelper(window, gEncryptionCert);
  258.   }
  259. }
  260.  
  261. function doHelpButton()
  262. {
  263.   openHelp('received_security');
  264. }
  265.